var listAll = []
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
    navbar_idx:3,
    show_navbar:true,
    arsmo:false,
    arsmoList:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */


  onLoad: function (t) {
    getApp().page.onLoad(this, t)
    this.init()
    this.init2()
  },
  typeClick(e){
    console.log(e);
    var idx = e.target.dataset.idx;
    if(this.data.type == e.target.dataset.item.id) return;
    this.setData({
      idx:idx,
      arsmo:false,
      type:e.target.dataset.item.id,
      list:listAll[idx] || []
    },function () {
      listAll[idx] || this.getList()
    })
  },
  typeClick2(){
    var t = this;
    this.setData({
      idx:5,
      arsmo:true,
      type:-1
    },t.getArsmo)
  },
  getArsmo(){
    var t = this;
    wx.request({
      url:'https://wxmall.sgwxmini.com/web/index.php?_acid=8&r=api/default/index',
      success(e){
        console.log(e.data);
        0 == e.data.code &&  t.setData({
          arsmoList:e.data.data
        })
      }
    })
  },
  init(){
    var t = this
    getApp().request({
      url:getApp().api.siteinfo.apiroot+'mall/cat',
      data:{_acid:getApp().api.siteinfo.acid},
      success(e){
        0 == e.code && t.setData({
          typeList:e.data.list
        },function () {
          console.log(e);
          t.typeClick({target:{dataset:{idx:0,item:e.data.list[0]}}})
        })
      }
    })
  },
  init2(){
    var t = this
    wx.request({
      url:getApp().api.siteinfo.apiroot+'action/arsmoProducts',
      data:{storeId:getApp().api.siteinfo.acid},
      success(e){
        0 == e.data.result && t.setData({
          arsmoTitle:e.data.title,
          arsmoShow:e.data.isShow
        })
      }
    })
  },
  getList(){
    var t = this
    wx.showLoading({title:'加载中...',mask:true})
    getApp().request({
      url: getApp().api.siteinfo.apiroot+'mall/goodcatlist',
      data:{
        cat_id:t.data.type,
        _acid:getApp().api.siteinfo.acid
      },
      success(e) {
        listAll[t.data.idx] = e.data.list
        t.setData({list:e.data.list})
        wx.hideLoading()
      }
    })

  },
  arsmoGo(){
    wx.navigateToMiniProgram({
      appId:'wxafcb42d9e9f6c19d'
    })
  },
  onPageScroll(){
    this.data.fix || this.setData({
      fix:true
    })
  },
  onMyEvent(){
    this.setData({fix:false})
  }
})
